<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../layui/layui.js" charset="utf-8"></script>
</head>

<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg-offset3" layui-col-lg6>
            <div class="layui-form layuimini-form">
                <form class="layui-form" action="" lay-filter="userForm">
                    <div class="layui-form-item">
                        <label class="layui-form-label">医生id：</label>
                        <div class="layui-input-block">
                            <input type="text" name="doctorId" id="doctorId" required lay-verify="required" placeholder="请输入医生id"
                                   autocomplete="off" class="layui-input" onblur="doctorsel()">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">医生姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="doctorName" id="doctorName" required lay-verify="required"  placeholder="医生姓名"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">患者id：</label>
                        <div class="layui-input-block">
                            <input type="text" name="userId" required lay-verify="required" placeholder="请输入患者id"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">患者姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="userName"placeholder="患者姓名"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <!-- id 隐藏 -->
                    <input type="hidden" name="id" value="" class="layui-input">



                    <div class="layui-form-item">
                        <label class="layui-form-label">患者病症：</label>
                        <div class="layui-input-block">
                            <input type="text" name="disease" required lay-verify="required" placeholder="患者病症"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">病症描述：</label>
                        <div class="layui-input-block">
                            <textarea name="description" placeholder="请输入病情" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">药品总价：</label>
                        <div class="layui-input-block">
                            <input type="text" name="totalPrice"    placeholder="药品总价"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否支付：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="payStatus" value="已支付" title="已支付" >
                            <input type="radio" name="payStatus" value="未支付" title="未支付" checked>
                        </div>
                    </div>
                    <div class="layui-form-item" id="hidden">
                        <label class="layui-form-label">支付方式：</label>
                        <div class="layui-input-block">
                            <select name="payType" lay-verify="required">
                                <option value=""></option>
                                <option value="微信支付">微信支付</option>
                                <option value="支付宝支付">支付宝支付</option>
                                <option value="现金支付">现金支付</option>
                            </select>
                        </div>
                    </div>

                    


                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>
<script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script language="javascript">
	function doctorsel(){
        var doctorId =$("#doctorId").val();
        // var data = JSON.parse(localStorage.getItem("PrescriptionItem"));
        $.ajax({
                "url":"http://localhost:8080/demo/user/userById?id="+doctorId,
                "success":function(result){
                    if(result.code==0){
                        $("#doctorName").value = result.data;
                        //layer.msg(result.msg);
                    }else{
                        //layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });
	}
	</script>


<script>
    
    //Demo
    layui.use('form', function () {
        // 表单对象 form
        var form = layui.form
            // jquery 对象 $
            , $ = layui.jquery;


             //监听提交
        form.on('text(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                "url":"http://localhost:8080/demo/prescription/insertPrescription",
                "data": data.field,
                "success":function(result){
                    if(result.code==0){

                        // 关闭弹出层
                         // 关闭 弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.msg("添加成功");
                        parent.layer.close(iframeIndex);
                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });























        var token = JSON.parse(localStorage.getItem("token"));

        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                "url":"http://localhost:8080/demo/prescription/insertPrescription",
                "data": data.field,
                "success":function(result){
                    if(result.code==0){

                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });
    });
</script>


</body>

</html>